Question 2

install.packages("plotly")
## Installing package into '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6'
## (as 'lib' is unspecified)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(tidyr)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
q2file="https://raw.githubusercontent.com/bcaffo/ds4ph-bme/master/data/classInterests.txt"
q2table=read.delim(q2file,header=TRUE,sep="")
gyear=ggplot(q2table,aes(x=as.factor(Year)))
gpro=ggplot(q2table,aes(x=as.factor(Program)))
gq2=ggplot(q2table,aes(x=as.factor(Year),fill=as.factor(Program)))
gq2=gq2+geom_bar(stat = 'count')
ggplotly(gq2)
library(reshape2)
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
q5file='https://raw.githubusercontent.com/jhu-advdatasci/2018/master/data/KFF/healthcare-spending.csv'
dat5=read.csv(url(q5file),skip=2,nrows=52)
#View(dat5)
colnames(dat5)[2:25]=substr(colnames(dat5[,2:25]),2,5)
dat5=dat5[-1,]%>%pivot_longer(-Location,names_to="year",values_to="spending")
g5=ggplot(dat5,aes(x=year,y=spending,fill=Location))
g5=g5+geom_col()
#g5=g5+theme(axis.text.x=element_text(angle=90,hjust=1))
ggplotly(g5)
dat6=dat5 %>% group_by(Location) %>% summarise(avgspending=mean(spending))
g6=ggplot(dat6,aes(x=Location,y=avgspending))+geom_col()+theme(axis.text.x = element_text(angle=90,hjust=1))
ggplotly(g6)